{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [],
   "source": [
    "# -*- coding = utf-8 -*-\n",
    "import requests\n",
    "import csv\n",
    "from bs4 import BeautifulSoup\n",
    "import time\n",
    "headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'}\n",
    "url='https://fe-api.zhaopin.com/c/i/sou?pageSize=90&cityId=530&salary=0,0&workExperience=-1&education=-1&companyType=-1&employmentType=-1&jobWelfareTag=-1&kw=python&kt=3&=0&_v=0.55809902&x-zp-page-request-id=9e29fc8c9037442d9da48959ce493e45-1568424495122-908331&x-zp-client-id=59f38e0d-13c9-4b53-9383-efffbbc78b28'\n",
    "r=requests.get(url,headers=headers)\n",
    "message=r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [],
   "source": [
    "result_list=[result['positionURL'] for result in message['data']['results']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_content(url):\n",
    "    headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'}\n",
    "    cookies_are=\"x-zp-client-id=59f38e0d-13c9-4b53-9383-efffbbc78b28; sts_deviceid=16bf5c6705ca2-0ff250439614f2-1333062-2073600-16bf5c6705d8e2; adfbid2=0; dywem=95841923.y; locationAuthorization=true; sts_sg=1; sts_chnlsid=Unknown; zp_src_url=https%3A%2F%2Fcrossincode.com%2Fvip%2Fhomework%2F30%2F; jobRiskWarning=true; dywec=95841923; __utmc=269921210; ZP_OLD_FLAG=false; POSSPORTLOGIN=7; CANCELALL=0; LastCity=%E5%8C%97%E4%BA%AC; LastCity%5Fid=530; urlfrom=121126445; urlfrom2=121126445; adfcid=none; adfcid2=none; adfbid=0; sts_sid=16d2d94524c9d6-01e64d155c5c8-e343166-2073600-16d2d94524d514; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22630559535%22%2C%22%24device_id%22%3A%2216bf5c6708d6c-0c79ec5acb6542-1333062-2073600-16bf5c6708ed0d%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E5%BC%95%E8%8D%90%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22https%3A%2F%2Fcrossincode.com%2Fvip%2Fhomework%2F30%2F%22%2C%22%24latest_referrer_host%22%3A%22crossincode.com%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC%22%7D%2C%22first_id%22%3A%2216bf5c6708d6c-0c79ec5acb6542-1333062-2073600-16bf5c6708ed0d%22%7D; acw_sc__v2=5d7c58c91c0e114995f5df1dc71e61fba5bbf5ff; dywea=95841923.4416474265946886000.1563196551.1568430261.1568432643.6; dywez=95841923.1568432643.6.6.dywecsr=crossincode.com|dyweccn=(referral)|dywecmd=referral|dywectr=undefined|dywecct=/vip/homework/30/; dyweb=95841923.1.10.1568432643; Hm_lvt_38ba284938d5eddca645bb5e02a02006=1568423328,1568430262,1568432643; __utma=269921210.86840498.1563196552.1568430262.1568432643.6; __utmz=269921210.1568432643.6.6.utmcsr=crossincode.com|utmccn=(referral)|utmcmd=referral|utmcct=/vip/homework/30/; __utmt=1; __utmb=269921210.1.10.1568432643; Hm_lpvt_38ba284938d5eddca645bb5e02a02006=1568432764; ZL_REPORT_GLOBAL={%22sou%22:{%22actionid%22:%2292ebd365-ef30-4569-a30f-0ca9963b815c-sou%22%2C%22funczone%22:%22smart_matching%22}%2C%22jobs%22:{%22recommandActionidShare%22:%22bd147bde-4141-45fe-a208-9cf6785addba-job%22%2C%22funczoneShare%22:%22dtl_best_for_you%22}%2C%22company%22:{%22actionid%22:%2253bf1047-0b06-4b60-97bb-6f79ff8ebea0-company%22%2C%22funczone%22:%22hiring_jd%22}}; sts_evtseq=45\"\n",
    "    cookies = dict(cookies_are=cookies_are)\n",
    "    try:    \n",
    "        r = requests.get(url, cookies=cookies,headers = headers)\n",
    "        soup = BeautifulSoup(r.text, 'html.parser')\n",
    "        title=soup.find('h3',class_='summary-plane__title').get_text()\n",
    "        salary=soup.find('h3',class_='summary-plane__salary').get_text()\n",
    "        content=soup.find('div',class_='describtion__detail-content').get_text()\n",
    "    except Exception as e:\n",
    "        print(e)\n",
    "        title='None'\n",
    "        salary='None'\n",
    "        content='None'\n",
    "    print('finished')\n",
    "    return [title,salary,content]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "'NoneType' object has no attribute 'get_text'\n",
      "finished\n",
      "'NoneType' object has no attribute 'get_text'\n",
      "finished\n",
      "'NoneType' object has no attribute 'get_text'\n",
      "finished\n",
      "'NoneType' object has no attribute 'get_text'\n",
      "finished\n"
     ]
    }
   ],
   "source": [
    "content_list=[]\n",
    "for index ,i in enumerate(result_list):\n",
    "    content_list.append(get_content(i))\n",
    "    time.sleep(3)\n",
    "print(content_list)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('zhilian.csv','w',encoding='utf_8_sig') as f:\n",
    "    cw= csv.writer(f)\n",
    "    cw.writerows(content_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
